import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:FiduMart/localization/app_export.dart';
import 'package:flutter_cupertino_datetime_picker/flutter_cupertino_datetime_picker.dart' as iOSDatePicker;

//日期选择器
class YearMonthPicker extends Dialog {
  final DateTime initialDate;
  final DateTime firstDate;
  final DateTime lastDate;
  final ValueChanged<DateTime> onDateChanged;

  YearMonthPicker({
    required this.initialDate,
    required this.firstDate,
    required this.lastDate,
    required this.onDateChanged,
  });
  late DateTime time;
  @override
  Widget build(BuildContext context) {
    return Container(
      color: ColorConstant.colorFF2D075A,
        child:Column(
        mainAxisSize: MainAxisSize.min,
        children: <Widget>[
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              SizedBox(
                width: 50,
              ),
              Text('date_filter'.tr,
                  textAlign: TextAlign.center,
                  style: TextStyle(fontSize: 18)),
              IconButton(
                icon: Icon(Icons.close),
                onPressed: () {
                  Get.back(); // 使用Get来关闭弹窗
                },
              ),
            ],
          ),
          Container(
            height: 220,
            child:
            // iOSDatePicker.DatePicker.showDatePicker(
            //   context,
            //   pickerMode: iOSDatePicker.DateTimePickerMode.date,
            //   minDateTime: DateTime(2012, 01),
            //   maxDateTime: DateTime(2032, 12),
            //   initialDateTime: initialDate,
            //   dateFormat: "yyyy MM",
            //   onConfirm: (DateTime dateTime, List<int> selectedIndex) {
            //     print("选择 $dateTime");
            //   },
            //   onCancel: () {},
            //   onClose: () {},
            //   onChange: (datetime, selectedIndex) {},
            // );
            // showDatePicker(context: context, firstDate: firstDate, lastDate: lastDate,builder: Theme(
            //   data: ThemeData(
            //
            //   ),
            // )),

            CupertinoDatePicker(
              mode: CupertinoDatePickerMode.monthYear,
              initialDateTime: initialDate,
              minimumDate: firstDate,
              maximumDate: lastDate,
              minimumYear: 2010,
              maximumYear: 2030,
              dateOrder: DatePickerDateOrder.ymd,
              onDateTimeChanged: (value){
                time = value;
              },
            ),
          ),
          GestureDetector(
            onTap: () {
              onDateChanged(time);
              Navigator.of(context).pop();
            },
            child: Container(
                height: 40,
                width: 140,
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(5),
                  gradient: LinearGradient(
                    colors: [
                      ColorConstant.blue_gradient_1,
                      ColorConstant.blue_gradient_2
                    ],
                    begin: Alignment.centerLeft, // 渐变色开始位置
                    end: Alignment.centerRight, // 渐变色结束位置
                  ),
                ),
                alignment: Alignment.center,
                child: Text(
                  'sure'.tr,
                  style: TextStyle(fontSize: 14),
                )),
          ),
          SizedBox(height: 40,)
        ],
      )
    );
  }
}